package com.xyhuo.leetcode.january;

import java.util.ArrayList;
import java.util.List;

/**
 * 验证回文串
 * https://leetcode.cn/problems/valid-palindrome/
 *
 * @time 2024/1/12
 */
public class IsPalindrome {

//    public static void main(String[] args) {
//        IsPalindrome ip = new IsPalindrome();
//        ip.isPalindrome("0P");
//    }

    public boolean isPalindrome(String s) {
        char[] charArray = s.toCharArray();
        List<Character> list = new ArrayList<>();
        for (int i = 0; i < charArray.length; i++) {
            if ((charArray[i] <= 'z' && charArray[i] >= 'a') || (charArray[i] <= '9' && charArray[i] >= '0')) {
                list.add(charArray[i]);
            } else if (charArray[i] <= 'Z' && charArray[i] >= 'A') {
                char val = (char) (32 + charArray[i]);
                list.add(val);
            }
        }
        for (int i = 0; i < list.size() / 2; i++) {
            if (list.get(i) != list.get(list.size() - 1 - i)) {
                return false;
            }
        }
        return true;
    }
}
